import {Injectable} from '@angular/core';
import {CookieService} from 'ng2-cookies';
@Injectable()
class User{
   userId:number;
   username:string;
   userType:number;
   auth:Array<number>;
   token:string;
   isSignIn:boolean;
   redirectTo:string;
  private cookie:CookieService=new CookieService();
   private static user:User;
  constructor (){

  }
  signOut(){
    this.isSignIn=false;
    this.cookie.delete('sid');
  }
  getToken(){
    return this.token||this.cookie.get('sid');
  }
  setUserId(userId:number){
    this.userId=userId;
  }
   setUserName(username:string){
     this.username=username;
   }
    setUserType(userType:number){
    this.userType=userType;
  }
  setAuth(auth:Array<number>){
    this.auth=auth;
  }
  setToken(token:string){
    this.token=token;
    this.cookie.set('sid',token);
  }
  setSignIn(status:boolean){
    this.isSignIn=status;
  }
  public static getInstance():User{
      if(!this.user){
        this.user=new User();
      }
    return this.user;
  }
}
export var user=User.getInstance();
